/*
 * HwndPainter.h
 *
 *  Created on: 2018年9月3日
 *      Author: zhengboyuan
 */

#ifndef WIN_HWNDPAINTER_H_
#define WIN_HWNDPAINTER_H_

#include "BasicType.h"
#include "ScaleContext.h"
#include <string>
#include "FfmpegUtil.h"


struct HwndPainterContext
{
	HWND hwnd;
	RECT rcWin;
	RECT rcDest;

	HDC hdc;

	int width;
	int height;
	int64_t pts;
	int64_t pkt_pts;

	int ratioX;
	int ratioY;
};


typedef void (*HwndPaintProc)(const HwndPainterContext& context, AVFrame* frame, void* user);


class HwndPainter
{
public:
	static RECT getScaleRect(const RECT& rc, int ratioX, int ratioY);

	static RECT getDestRect(int picWidth, int picHeight,
		int destWidth, int destHeight,
		int ratioX, int ratioY);

public:
	HwndPainter();
	virtual ~HwndPainter();

	void reset();

	void setRatio(int ratioX, int ratioY);

	bool draw(HWND hwnd, HDC hdc, AVFrame* pFrame, HwndPaintProc proc, void* user);

	void drawBackground(HWND hwnd, HDC hdc = NULL);

protected:
	bool drawFrame(HWND hwnd, HDC hdc, AVFrame* pFrame, HwndPaintProc proc, void* user);

	void resetPicture(int width, int height);

	void drawPicture(HWND hwnd, HDC hdc, const RECT& rcWin, const RECT& rc, AVPicture& pic, AVFrame* frame, HwndPaintProc proc, void* user);

protected:
	HwndPainterContext	m_paintContext;

	ScaleContext    m_scaleContext;

	AVPicture       m_picture;

	int m_maxWidth;
	int m_maxHeight;

	BITMAPINFO  m_bmpInfo;
	HBRUSH		m_brush;

};

#endif /* WIN_HWNDPAINTER_H_ */
